﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.IO;
using System.Drawing;
using LEDManager;
using System.Text;
using System.Windows.Forms;
using LEDHelper;
using System.Threading;
public partial class LEDSVCWIN
{
    public static log4net.ILog log = log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    LEDConsole3 led;
    ArrayList textlist = new ArrayList();
    ArrayList fontlist = new ArrayList();
    private void SaveToFile(byte[] value, string szBmp)
    {
        string file = System.IO.Path.Combine(PathHelper.ApplicationPath, @"SXDFile\") + szBmp;
        if (System.IO.File.Exists(file))
        {
            System.IO.File.Delete(file);
        }
        System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.OpenOrCreate);
        fs.Write(value, 0, value.Length);
        fs.Flush();
        fs.Close();
    }
    private Bitmap BitmapFromByteArray(byte[] byteArray)
    {
        int n = 0;
        // Get the width
        uint x = (((uint)byteArray[n] * 256 + (uint)byteArray[n + 1]) * 256 + (uint)byteArray[n + 2]) * 256 + (uint)byteArray[n + 3];
        int width = (int)x;
        n += 4;
        // Get the height
        x = (((uint)byteArray[n] * 256 + (uint)byteArray[n + 1]) * 256 + (uint)byteArray[n + 2]) * 256 + (uint)byteArray[n + 3];
        int height = (int)x;
        n += 4;
        // Create the Bitmmap object
        Bitmap bmp = new Bitmap(width, height);
        // The pixels are stored in order by rows
        for (int j = 0; j < height; j++)
        {
            // Read the pixels for each row
            for (int i = 0; i < width; i++)
            {
                x = (((uint)byteArray[n] * 256 + (uint)byteArray[n + 1]) * 256 + (uint)byteArray[n + 2]) * 256 + (uint)byteArray[n + 3];
                bmp.SetPixel(i, j, Color.FromArgb((int)x));
                n += 4;
            }
        }
        return bmp;
    }
    string fileplay = Path.Combine(PathHelper.ApplicationPath, @"SXDFile\InBoard.dat");
    string filebmp = Path.Combine(PathHelper.ApplicationPath, @"SXDFile\Temp\ScreenCopy.jpg");
    public string GetFileStream(string filep)
    {
        string result = "-1";
        if (!System.IO.File.Exists(filep))
            return result;
        /*
        StreamReader reader = new StreamReader(file);
        result = reader.ReadToEnd();
        if (result.Trim() == "")
            result = "-1";
        reader.Close();
        reader.Dispose();*/ 
 
        FileStream stream1 = File.Open(filep, FileMode.Open, FileAccess.Read, FileShare.Read);
        byte[] buffer1 = new byte[stream1.Length];
        stream1.Read(buffer1, 0, (int)stream1.Length);
        stream1.Close();
        string base64String = Convert.ToBase64String(buffer1); 
        result= base64String;
        if (result == "")
            result = "-1";
        return result;
    }
    private string CheckLEDConsole(int IsUseIP=1,int reset=0)
    {
        string result = "";
        if(!System.IO.Directory.Exists(Path.Combine(PathHelper.ApplicationPath, @"SXDFile")))
        {
            System.IO.Directory.CreateDirectory(Path.Combine(PathHelper.ApplicationPath, @"SXDFile"));
        }
        if (!System.IO.Directory.Exists(Path.Combine(PathHelper.ApplicationPath, @"SXDFile\Temp")))
        {
            System.IO.Directory.CreateDirectory(Path.Combine(PathHelper.ApplicationPath, @"SXDFile\Temp"));
        }
        #region=====================
        if (led == null)
        {
            led = new LEDConsole3();
            textlist = new ArrayList();
            textlist.Add(" 0 = 随机");
            textlist.Add("1立即显示");
            textlist.Add("2左滚显示");
            textlist.Add("3上滚显示");
            textlist.Add("4右滚显示");
            textlist.Add("5下滚显示");
            textlist.Add("6连续左滚显示");
            textlist.Add("7连续下滚显示");
            textlist.Add("8中间向上下展开");
            textlist.Add("9中间向两边展开");
            textlist.Add("10中间向四周展开");
            textlist.Add("11从右向左移入'");
            textlist.Add("12从左向右移入");
            textlist.Add("13从左向右展开");
            textlist.Add("14从右向左展开");
            textlist.Add("15从右上角移入");
            textlist.Add("16从右下角移入");
            textlist.Add("17从左上角移入");
            textlist.Add("18从左下角移入");
            textlist.Add("19从上向下移入");
            textlist.Add("20从下向上移入");
            textlist.Add("21横向百叶窗");
            textlist.Add("22纵向百叶窗'");
            textlist.Add("23普通消息,地铁免费啦.");
            textlist.Add("24断电后持续:珍惜生命，严禁酒后驾车。开车时请您系好安全带。");
            textlist.Add("25紧急通知:地铁收费啦。");
            fontlist.Add("宋体");
            fontlist.Add("楷体");
            fontlist.Add("黑体");
        }
        //led.XLED_Startup(); 
        if (reset == 1)
        {
            led.ResetLedData();
        }
        if (IsUseIP == 1)
        {
            led.IsUseLEDbyIP = 1;
        }
        result = "Service Started";
        #endregion
        return result;
    }
    public object SendLED(string ctype, Dictionary<string, string> para)
    {
        object result = "-1";
        string nLEDID = "1";
        int iValue = 0;
        int iOUTPUTIP = 0;
        int iPower = 0;
        string szBmpFile = "";
        string RootType, ColorMode, survive;
        string ActionMode;
        Int32 ChapterIndex, RegionIndex, LeafIndex, ObjectIndex;
        ushort num;
        UInt32 time;
        string wait;
        Int32 startx, starty, width, height, border, vertical, stretch;
        string fontstyle, bordershape;
        Int32 transparent, fontcolor, fontsize, wordwrap, alignment, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime;
        string fontname, text, picture, format;
        Int32 src_width, src_height;
        Int32 year_offset, month_offset, day_offset, sec_offset;
        Int32 offset, dotradius, adotwidth, bdotwidth, cdotwidth, hourwidth, minutewidth, secondwidth;
        UInt32 bkcolor, bordercolor, borderwidth, adotcolor, bdotcolor, cdotcolor, minutecolor, secondcolor, hourcolor, cdotvisible;

        int iTextid = 0;
        CheckLEDConsole();
        switch (ctype)
        {
            case "LED_GetLEDList":
                result = led.LED_GetLEDList();
                break;
            case "LED_GetText":
                iTextid = System.Convert.ToInt32(para["TEXTID"].ToString());
                result = textlist[iTextid];
                break;
            case "LED_Registration":
                #region=====================
                #endregion
                nLEDID = para["LEDID"].ToString();
                string Lprefix = System.Convert.ToString(para["LLLEDPRE"].ToString());
                string Lnumber = System.Convert.ToString(para["LLLEDNUMBER"].ToString());
                string mac = System.Convert.ToString(para["MACADDRESS"].ToString());
                string ip = System.Convert.ToString(para["IPADDRESS"].ToString());
                string devtyp = System.Convert.ToString(para["DEVTYPE"].ToString());
                string bit = System.Convert.ToString(para["DSPEED"].ToString());
                string locport = System.Convert.ToString(para["LOCPORT"].ToString());
                string comport = System.Convert.ToString(para["COMPORT"].ToString());
                string stype = System.Convert.ToString(para["LLSCREENTYPE"].ToString());
                string rmtport = System.Convert.ToString(para["REMOTPORT"].ToString());
                string dstAdd = System.Convert.ToString(para["DSTADD"].ToString());
                string Lwidth = System.Convert.ToString(para["WIDTH"].ToString());
                string Lheight = System.Convert.ToString(para["HEIGHT"].ToString());
                string nuser = System.Convert.ToString(para["NEWDATE"].ToString());
                string ndate = System.Convert.ToString(para["NEWUSER"].ToString());
                string cuser = System.Convert.ToString(para["LASTDATE"].ToString());
                string cdate = System.Convert.ToString(para["LASTUSER"].ToString());
                result = led.LED_Registration(nLEDID, Lprefix, Lnumber, ip, mac, devtyp, bit, locport, comport, stype, rmtport, dstAdd, Lwidth, Lheight, nuser, ndate, cuser, cdate);
                log.Info("LED_Registration");
                break;
            case "LED_GetFont":
                iTextid = System.Convert.ToInt32(para["FONTID"].ToString());
                result = fontlist[iTextid];
                break;
            case "LED_SavePicture":
                szBmpFile = para["PICTURENAME"].ToString();
                string file = szBmpFile;
                string patternStr = para["PVALUE"].ToString();
                byte[] ba = Convert.FromBase64String(patternStr);
                //Image  bmp = BitmapFromByteArray(ba);
                SaveToFile(ba, file);
                result = 0;
                break;
            case "ResetLedData":
                led.ResetLedData();
                break;
            case "LED_Startup":                               
                int reset= System.Convert.ToInt32(para["RESETDATA"].ToString());              
                int ipused= System.Convert.ToInt32(para["USELEDBYIP"].ToString());
                result = CheckLEDConsole(ipused,reset); 
                break;
            case "LED_Cleanup":
                led.XLED_Cleanup();
                led = null;
                result = "0";
                break;
            ////设置控制卡电源 value=LED_POWER_ON表示开启电源 value=LED_POWER_OFF表示关闭电源
            case "LED_SetPower":
                nLEDID = para["LEDID"].ToString();
                iPower = System.Convert.ToInt32(para["POWER"].ToString());
                if (para.ContainsKey("OUTPUTIP"))
                {
                    iOUTPUTIP = System.Convert.ToInt32(para["OUTPUTIP"].ToString());
                }
                result = led.LED_SetPower(nLEDID, iPower, iOUTPUTIP);
                break;
            //读取控制卡电源状态
            case "LED_GetPower":
                nLEDID = para["LEDID"].ToString();
                result = led.LED_GetPower(nLEDID);
                break;
            case "LED_PreviewFile":
                nLEDID = para["LEDID"].ToString();
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                result = led.LED_PreviewFile(nLEDID,width,height,fileplay);
                break;
            case "LED_GetScreenCopy":
                nLEDID = para["LEDID"].ToString();
                result = led.LED_GetScreenCopy(nLEDID, filebmp);
                break;                 
            //读取控制卡电源状态
            case "LED_GetTypeOfContent":
                nLEDID = para["LEDID"].ToString();
                result = led.LED_GetTypeOfContent(nLEDID);
                break; 
            case "LED_ResetDisplay":
                nLEDID = para["LEDID"].ToString();
                result = led.LED_ResetDisplay(nLEDID);
                break;
            //设置控制卡亮度 value取值范围0-7
            case "LED_SetBright":
                nLEDID = para["LEDID"].ToString();
                iValue = System.Convert.ToInt32(para["BRIGHT"].ToString());
                result = led.LED_SetBright(nLEDID, iValue);
                break;
            //读取控制卡亮度
            case "LED_GetBright":
                nLEDID = para["LEDID"].ToString();
                result = led.LED_GetBright(nLEDID);
                break;
            case "LED_AdjustTime":
                nLEDID = para["LEDID"].ToString();
                result = led.LED_AdjustTime(nLEDID);
                break;
            case "LED_GetPlayContent":
                nLEDID = para["LEDID"].ToString();
                if (System.IO.File.Exists(fileplay))
                {
                    System.IO.File.Delete(fileplay);
                }
                result = led.LED_GetPlayContent(nLEDID, fileplay);
                result = "-1";
                break;
            case "LED_GetFileContent":
                nLEDID = para["LEDID"].ToString();
                result = GetFileStream(fileplay); 
                break;
            case "LED_MakeRoot":
                #region===========================
                nLEDID = para["LEDID"].ToString();
                RootType = System.Convert.ToString(para["ROOTTYPE"].ToString());
                ColorMode = System.Convert.ToString(para["COLORMODE"].ToString());
                survive = System.Convert.ToString(para["SURVIVE"].ToString());
                string msgtype = System.Convert.ToString(para["MSGTYPE"].ToString());
                result = led.LED_MakeRoot(nLEDID, RootType, ColorMode, survive, msgtype);
                break;
                #endregion
            case "LED_MakeLeaf":
                #region===========================
                nLEDID = para["LEDID"].ToString();
                RootType = System.Convert.ToString(para["ROOTTYPE"].ToString());
                ActionMode = System.Convert.ToString(para["ACTIONMODE"].ToString());
                ChapterIndex = System.Convert.ToInt32(para["CHAPTERINDEX"].ToString());
                RegionIndex = System.Convert.ToInt32(para["REGIONINDEX"].ToString());
                LeafIndex = System.Convert.ToInt32(para["LEAFINDEX"].ToString());
                ColorMode = System.Convert.ToString(para["COLORMODE"].ToString());
                time = System.Convert.ToUInt32(para["TIME"].ToString());
                ColorMode = System.Convert.ToString(para["COLORMODE"].ToString());
                wait = System.Convert.ToString(para["WAIT"].ToString());
                result = led.LED_MakeLeaf(nLEDID, RootType, ActionMode, ChapterIndex, RegionIndex, LeafIndex, ColorMode, time, wait);
                break;
                #endregion
            case "LED_MakeChapter":
                #region===========================
                nLEDID = para["LEDID"].ToString();
                RootType = System.Convert.ToString(para["ROOTTYPE"].ToString());
                ActionMode = System.Convert.ToString(para["ACTIONMODE"].ToString());
                ChapterIndex = System.Convert.ToInt32(para["CHAPTERINDEX"].ToString());
                ColorMode = System.Convert.ToString(para["COLORMODE"].ToString());
                time = System.Convert.ToUInt32(para["TIME"].ToString());
                ColorMode = System.Convert.ToString(para["COLORMODE"].ToString());
                wait = System.Convert.ToString(para["WAIT"].ToString());
                result = led.LED_MakeChapter(nLEDID, RootType, ActionMode, ChapterIndex, ColorMode, time, wait);
                break;
                #endregion

            case "LED_AddChapter":
                #region===========================
                //LED_AddChapter(int nLEDID, int num, UInt32 time, string wait)
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                time = System.Convert.ToUInt32(para["TIME"].ToString());
                wait = System.Convert.ToString(para["WAIT"].ToString());
                result = led.LED_AddChapter(nLEDID, num, time, wait);
                break;
                #endregion
            case "LED_AddChapterEx":
                #region===========================
                //LED_AddChapter(int nLEDID, int num, UInt32 time, string wait)
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                time = System.Convert.ToUInt32(para["TIME"].ToString());
                wait = System.Convert.ToString(para["WAIT"].ToString());
                ushort kind = System.Convert.ToUInt16(para["KIND"].ToString());
                ushort week = System.Convert.ToUInt16(para["WEEK"].ToString());
                Int32 stime = System.Convert.ToInt32(para["STIME"].ToString());
                Int32 sdate = System.Convert.ToInt32(para["SDATE"].ToString());
                Int32 etime = System.Convert.ToInt32(para["ETIME"].ToString());
                Int32 edate = System.Convert.ToInt32(para["EDATE"].ToString());
                result = led.LED_AddChapterEx(nLEDID, num, time, wait, kind, week, stime, sdate, etime, edate);
                break;
                #endregion
            case "LED_AddRegion":
                #region===========================
                //LED_AddChapter(int nLEDID, int num, UInt32 time, string wait)
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                result = led.LED_AddRegion(nLEDID, num, startx, starty, width, height, border);
                #endregion
                break;
            case "LED_AddLeaf":
                #region===========================
                //LED_AddChapter(int nLEDID, int num, UInt32 time, string wait)
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                time = System.Convert.ToUInt32(para["TIME"].ToString());
                wait = System.Convert.ToString(para["WAIT"].ToString());
                result = led.LED_AddLeaf(nLEDID, num, time, wait);
                #endregion
                break;

            case "LED_AddTextB":
                #region===========================
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                text = System.Convert.ToString(para["TEXT"].ToString());
                fontname = System.Convert.ToString(para["FONTNAME"].ToString());
                fontsize = System.Convert.ToInt32(para["FONTSIZE"].ToString());
                fontcolor = System.Convert.ToInt32(para["FONTCOLOR"].ToString());
                fontstyle = System.Convert.ToString(para["FONTSTYLE"].ToString());
                wordwrap = System.Convert.ToInt32(para["WORDWRAP"].ToString());
                alignment = System.Convert.ToInt32(para["ALIGNMENT"].ToString());
                inmethod = System.Convert.ToInt32(para["INMETHOD"].ToString());
                inspeed = System.Convert.ToInt32(para["INSPEED"].ToString());
                outmethod = System.Convert.ToInt32(para["OUTMETHOD"].ToString());
                outspeed = System.Convert.ToInt32(para["OUTSPEED"].ToString());
                stopmethod = System.Convert.ToInt32(para["STOPMETHOD"].ToString());
                stopspeed = System.Convert.ToInt32(para["STOPSPEED"].ToString());
                stoptime = System.Convert.ToInt32(para["STOPTIME"].ToString());
                //text = System.Text.Encoding.GetEncoding(936).GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(text as string));
                //fontname = System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(fontname as string));
                result = led.LED_AddTextB(nLEDID, num, startx, starty, width, height, transparent, border, text, fontname, fontsize, fontcolor, fontstyle, wordwrap, alignment, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
                #endregion
                break;
            case "LED_AddText":
                #region===========================
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                text = System.Convert.ToString(para["TEXT"].ToString());
                fontname = System.Convert.ToString(para["FONTNAME"].ToString());
                fontsize = System.Convert.ToInt32(para["FONTSIZE"].ToString());
                fontcolor = System.Convert.ToInt32(para["FONTCOLOR"].ToString());
                fontstyle = System.Convert.ToString(para["FONTSTYLE"].ToString());
                wordwrap = System.Convert.ToInt32(para["WORDWRAP"].ToString());
                alignment = System.Convert.ToInt32(para["ALIGNMENT"].ToString());
                inmethod = System.Convert.ToInt32(para["INMETHOD"].ToString());
                inspeed = System.Convert.ToInt32(para["INSPEED"].ToString());
                outmethod = System.Convert.ToInt32(para["OUTMETHOD"].ToString());
                outspeed = System.Convert.ToInt32(para["OUTSPEED"].ToString());
                stopmethod = System.Convert.ToInt32(para["STOPMETHOD"].ToString());
                stopspeed = System.Convert.ToInt32(para["STOPSPEED"].ToString());
                stoptime = System.Convert.ToInt32(para["STOPTIME"].ToString());
                //text = System.Text.Encoding.GetEncoding(936).GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(text as string));
                //fontname = System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(fontname as string));
                result = led.LED_AddText(nLEDID, num, startx, starty, width, height, transparent, border, text, fontname, fontsize, fontcolor, fontstyle, wordwrap, alignment, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
                #endregion
                break;
            case "LED_AddDateTimeEx":
                #region=====================  
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                vertical = System.Convert.ToInt32(para["VERTICAL"].ToString());
                fontname = System.Convert.ToString(para["FONTNAME"].ToString());
                fontsize = System.Convert.ToInt32(para["FONTSIZE"].ToString());
                fontcolor = System.Convert.ToInt32(para["FONTCOLOR"].ToString());
                fontstyle = System.Convert.ToString(para["FONTSTYLE"].ToString());
                year_offset = System.Convert.ToInt32(para["YEAR_OFFSET"].ToString());
                month_offset = System.Convert.ToInt32(para["MONTH_OFFSET"].ToString());
                day_offset = System.Convert.ToInt32(para["DAY_OFFSET"].ToString());
                sec_offset = System.Convert.ToInt32(para["SEC_OFFSET"].ToString());
                format = System.Convert.ToString(para["FORMAT"].ToString());
                //fontname = System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(fontname as string));
                //format = System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(format as string));
                //format = System.Text.Encoding.GetEncoding(950).GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(format as string));
                //System.Text.Encoding GB2312 = System.Text.Encoding.GetEncoding("GB2312");
                //System.Text.Encoding UTF8 = System.Text.Encoding.Unicode;
                //format       =       GB2312.GetString(UTF8.GetBytes(format));   
                //format       =       UTF8.GetString((System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(format as string)));   
                result = led.LED_AddDateTimeEx(nLEDID, num, startx, starty, width, height, transparent, border, vertical, fontname, fontsize, fontcolor, fontstyle,
                year_offset, month_offset, day_offset, sec_offset, format);
                      #endregion
                break;
            case "LED_AddTextEx":
                #region===========================
                /*
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                Int32 flag = System.Convert.ToInt32(para["FLAG"].ToString());
                text = System.Convert.ToString(para["TEXT"].ToString());
                fontname = System.Convert.ToString(para["FONTNAME"].ToString());
                fontsize = System.Convert.ToInt32(para["FONTSIZE"].ToString());
                fontcolor = System.Convert.ToInt32(para["FONTCOLOR"].ToString());
                fontstyle = System.Convert.ToString(para["FONTSTYLE"].ToString());
                wordwrap = System.Convert.ToInt32(para["WORDWRAP"].ToString());
                vertical = System.Convert.ToInt32(para["VERTICAL"].ToString());
                alignment = System.Convert.ToInt32(para["ALIGNMENT"].ToString());
               Int32 verticalspace = System.Convert.ToInt32(para["VERTICALSPACE"].ToString());
                Int32 horizontalfit = System.Convert.ToInt32(para["HORIZONTALFIT"].ToString());
                
                inmethod = System.Convert.ToInt32(para["INMETHOD"].ToString());
                inspeed = System.Convert.ToInt32(para["INSPEED"].ToString());
                outmethod = System.Convert.ToInt32(para["OUTMETHOD"].ToString());
                outspeed = System.Convert.ToInt32(para["OUTSPEED"].ToString());
                stopmethod = System.Convert.ToInt32(para["STOPMETHOD"].ToString());
                stopspeed = System.Convert.ToInt32(para["STOPSPEED"].ToString());
                stoptime = System.Convert.ToInt32(para["STOPTIME"].ToString());
                result = led.LED_AddTextEx3(nLEDID, num, startx, starty, width, height, transparent,flag,  text, fontname, fontsize, fontcolor, fontstyle, bkcolor,wordwrap,vertical,
                    alignment, verticalspace, horizontalfit, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
                
                           text = System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(text as string));
                fontname = System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(fontname as string));*/
                #endregion
                break;
            case "LED_AddWindow":
                #region===========================
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                picture = System.Convert.ToString(para["PICTURE"].ToString());
                src_width = System.Convert.ToInt32(para["SWIDTH"].ToString());
                src_height = System.Convert.ToInt32(para["SHEIGHT"].ToString());
                alignment = System.Convert.ToInt32(para["ALIGNMENT"].ToString());
                inmethod = System.Convert.ToInt32(para["INMETHOD"].ToString());
                inspeed = System.Convert.ToInt32(para["INSPEED"].ToString());
                outmethod = System.Convert.ToInt32(para["OUTMETHOD"].ToString());
                outspeed = System.Convert.ToInt32(para["OUTSPEED"].ToString());
                stopmethod = System.Convert.ToInt32(para["STOPMETHOD"].ToString());
                stopspeed = System.Convert.ToInt32(para["STOPSPEED"].ToString());
                stoptime = System.Convert.ToInt32(para["STOPTIME"].ToString());
                result = led.LED_AddWindow(nLEDID, num, startx, starty, width, height, transparent, border, picture, src_width, src_height,
                    alignment, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
                #endregion
                break;
            case "LED_AddPicture":
                #region=====================
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                picture = System.Convert.ToString(para["PICTURE"].ToString());
                alignment = System.Convert.ToInt32(para["ALIGNMENT"].ToString());
                inmethod = System.Convert.ToInt32(para["INMETHOD"].ToString());
                inspeed = System.Convert.ToInt32(para["INSPEED"].ToString());
                outmethod = System.Convert.ToInt32(para["OUTMETHOD"].ToString());
                outspeed = System.Convert.ToInt32(para["OUTSPEED"].ToString());
                stopmethod = System.Convert.ToInt32(para["STOPMETHOD"].ToString());
                stopspeed = System.Convert.ToInt32(para["STOPSPEED"].ToString());
                stoptime = System.Convert.ToInt32(para["STOPTIME"].ToString());
                result = led.LED_AddPicture(nLEDID, num, startx, starty, width, height, transparent, border, picture
                    , alignment, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
                break;
                #endregion
            case "LED_AddMovie":
                #region=====================
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                picture = System.Convert.ToString(para["PICTURE"].ToString());
                stretch = System.Convert.ToInt32(para["STRETCH"].ToString());

                result = led.LED_AddMovie(nLEDID, num, startx, starty, width, height, transparent, border, picture, stretch);
                 #endregion
                break;
            case "LED_MakeObject":
                #region=====================
                nLEDID = para["LEDID"].ToString();
                RootType = System.Convert.ToString(para["ROOTTYPE"].ToString());
                ActionMode = System.Convert.ToString(para["ACTIONMODE"].ToString());
                ChapterIndex = System.Convert.ToInt32(para["CHAPTERINDEX"].ToString());
                RegionIndex = System.Convert.ToInt32(para["REGIONINDEX"].ToString());
                LeafIndex = System.Convert.ToInt32(para["LEAFINDEX"].ToString());
                ObjectIndex = System.Convert.ToInt32(para["OBJECTINDEX"].ToString());
                ColorMode = System.Convert.ToString(para["COLORMODE"].ToString());
                result = led.LED_MakeObject(nLEDID, RootType, ActionMode, ChapterIndex, RegionIndex, LeafIndex, ObjectIndex, ColorMode);
                #endregion
                break;

            case "LED_AddClockEx2":
                #region=====================
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                startx = System.Convert.ToInt32(para["STARTX"].ToString());
                starty = System.Convert.ToInt32(para["STARTY"].ToString());
                width = System.Convert.ToInt32(para["WIDTH"].ToString());
                height = System.Convert.ToInt32(para["HEIGHT"].ToString());
                transparent = System.Convert.ToInt32(para["TRANSPARENT"].ToString());
                border = System.Convert.ToInt32(para["BORDER"].ToString());
                vertical = System.Convert.ToInt32(para["VERTICAL"].ToString());
                offset = System.Convert.ToInt32(para["OFFSET"].ToString());
                bkcolor = System.Convert.ToUInt32(para["BKCOLOR"].ToString());
                bordercolor = System.Convert.ToUInt32(para["BORDERCOLOR"].ToString());
                borderwidth = System.Convert.ToUInt32(para["BORDERWIDTH"].ToString());
                bordershape = System.Convert.ToString(para["BORDERSHAPE"].ToString());
                dotradius = System.Convert.ToInt32(para["DOTRADIUS"].ToString());
                adotwidth = System.Convert.ToInt32(para["ADOTWIDTH"].ToString());
                adotcolor = System.Convert.ToUInt32(para["ADOTCOLOR"].ToString());
                bdotwidth = System.Convert.ToInt32(para["BDOTWIDTH"].ToString());
                bdotcolor = System.Convert.ToUInt32(para["BDOTCOLOR"].ToString());
                cdotvisible = System.Convert.ToUInt32(para["CDOTVISIBLE"].ToString());
                bdotwidth = System.Convert.ToInt32(para["CDOTWIDTH"].ToString());
                cdotwidth = System.Convert.ToInt32(para["BDOTWIDTH"].ToString());
                cdotcolor = System.Convert.ToUInt32(para["CDOTCOLOR"].ToString());
                hourwidth = System.Convert.ToInt32(para["HOURWIDTH"].ToString());
                hourcolor = System.Convert.ToUInt32(para["HOURCOLOR"].ToString());
                minutewidth = System.Convert.ToInt32(para["MINUTEWIDTH"].ToString());
                minutecolor = System.Convert.ToUInt32(para["MINUTECOLOR"].ToString());
                secondwidth = System.Convert.ToInt32(para["SECONDWIDTH"].ToString());
                secondcolor = System.Convert.ToUInt32(para["SECONDCOLOR"].ToString());
                result = led.LED_AddClockEx2(nLEDID, num, startx, starty, width, height, transparent, border, vertical, offset, bkcolor, bordercolor, borderwidth, bordershape,
                dotradius, adotwidth, adotcolor, bdotwidth, bdotcolor, cdotvisible, cdotwidth, cdotcolor,
                hourwidth, hourcolor, minutewidth, minutecolor, secondwidth, secondcolor);
                #endregion
                break;
            case "LED_SendToScreen":
                //LED_AddChapter(int nLEDID, int num, UInt32 time, string wait)
                nLEDID = para["LEDID"].ToString();
                num = System.Convert.ToUInt16(para["PNUM"].ToString());
                int zip = System.Convert.ToUInt16(para["ZIP"].ToString());
                result = led.LED_SendToScreen(nLEDID, num, zip);
                break;
            default:
                result = "request command can'f find";
                break;

        }
        return result;
    }
}


